blob: 6b583e5102b1c656bfacc57c39fc5ce155b6bd8a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import { createContextFromRequest } from "@/server/api/client";
import { and, eq } from "drizzle-orm";
import { db } from "@hoarder/db";
import { assets } from "@hoarder/db/schema";
export const dynamic = "force-dynamic";
export async function GET(
request: Request,
{ params }: { params: { assetId: string } },
) {
const ctx = await createContextFromRequest(request);
if (!ctx.user) {
return Response.json({ error: "Unauthorized" }, { status: 401 });
}
const asset = await db.query.assets.findFirst({
where: and(eq(assets.id, params.assetId), eq(assets.userId, ctx.user.id)),
});
if (!asset) {
return Response.json({ error: "Asset not found" }, { status: 404 });
}
return new Response(asset.blob as string, {
status: 200,
headers: {
"Content-type": asset.contentType,
},
});
}
|